
package section2.sparsematmult;
import jgfutil.*;

public class SparseMatmultOCL
{

  native float[] sparseFromC(int nthreads, float val[], int row[],int col[], float x[], float y[], int NUM_ITERATIONS, int lowsum[], int highsum[], int nz_size, int n_size, int m_size); 

  static {
  	System.loadLibrary("sparse");
  }


  public float ytotal = 0;
  public float yt[];

	/* 10 iterations used to make kernel have roughly
		same granulairty as other Scimark kernels. */

	public float test( float y[], float val[], int row[],
				int col[], float x[], int NUM_ITERATIONS, int lowsum[], int highsum[])
	{


        JGFInstrumentor.startTimer("Section2:SparseMatmult:Kernel"); 
        yt = sparseFromC(JGFSparseMatmultOCLBench.nthreads,val,row,col,x,y,NUM_ITERATIONS, lowsum,highsum, val.length, x.length, y.length);
        JGFInstrumentor.stopTimer("Section2:SparseMatmult:Kernel"); 
          
          for (int i=0; i<val.length; i++) {
            ytotal += yt[ row[i] ];
          }
		return ytotal;
	}
}




